package demo1;

public class Test3 {
    public static void main(String[] args) {
        System.out.println(sqrt(3));
    }
    public static int sqrt (int x) {
        if(x == 0 ) return 0 ;
        // write code here
        int left = x ;
        int right = 1 ;
        int mid = (left + right) / 2 ;

        while(left >= right){

            if((mid < x/mid && (mid+1) > x/(mid+1) ) ){
                break ;
            }else if(mid  > x / mid){
            left -- ;
            }else if(mid < x/mid){
               right++ ;
            }
          mid = (left+ right)/2 ;

        }
        return mid ;
    }
}
